package com.wenwan.manage.controller;

import java.io.IOException;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.wenwan.manage.service.AuthenticationService;
import com.wenwan.manage.setting.DefaultValue;

import javax.annotation.Resource;

/**
 * 用户认证
 * 
 * @author Admin
 *
 * @param
 */
@Controller
@RequestMapping(value = "/authentication")
public class AuthenticationController {

	@Autowired
	private AuthenticationService authenticationService;

	/**
	 * 检测身份证
	 * 
	 * @param userId
	 * @param multipartFile
	 * @param card_type
	 * @return
	 * @throws IOException
	 */
	@ResponseBody
	@RequestMapping(value = "/check/id/card", method = { RequestMethod.POST })
	public Map<String, Object> checkIdCard(@RequestParam(required = true) String userId,
			@RequestParam MultipartFile multipartFile, @RequestParam(required = true) Integer card_type,
			@RequestParam(required = true) String token) throws IOException {
		return authenticationService.checkIdCard(userId, multipartFile.getBytes(), multipartFile.getOriginalFilename(),
				card_type, token);
		// return RenLiangHeShengUtil.checkIdCard(userId, multipartFile, card_type,
		// token);
	}

	/**
	 * 获取活体栓测码
	 * 
	 * @param userId
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/face/livegetfour", method = { RequestMethod.POST })
	public Map<String, Object> faceLivegetfour(@RequestParam(required = true) String userId,
			@RequestParam(required = true) String token) {
		return authenticationService.faceLivegetfour(userId, token);
		// return RenLiangHeShengUtil.faceLivegetfour(userId, token);
	}

	/**
	 * 活体检测
	 * 
	 * @param userId
	 * @param validate_data
	 * @param video
	 * @param compare_flag
	 * @param card
	 * @param seq
	 * @return
	 * @throws IOException
	 */
	@ResponseBody
	@RequestMapping(value = "/face/live/detect/four", method = { RequestMethod.POST })
	public Map<String, Object> faceLiveDetectFour(@RequestParam(required = true) String userId,
			@RequestParam(required = true) String validate_data, @RequestParam MultipartFile video,
			@RequestParam(required = false, defaultValue = DefaultValue.FALSE) Boolean compare_flag,
			@RequestParam(required = false) String seq, @RequestParam(required = true) String token)
			throws IOException {
		return authenticationService.faceLiveDetectFour2(userId, validate_data, video.getBytes(),
				video.getOriginalFilename(), compare_flag, seq, token);
		// return faceLiveDetectFour2(userId, validate_data, video, compare_flag, seq,
		// token);
	}

	/**
	 * 开始检测
	 * 
	 * @param userId
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/start/authentication", method = { RequestMethod.POST })
	public Map<String, Object> startAuthentication(@RequestParam(required = true) String userId) {
		return authenticationService.startAuthentication(userId);
		// return RenLiangHeShengUtil.startAuthentication(userId);
	}

}
